/*
 * @Author: NtyAaron
 * @Date: 2021-04-12 11:13:45
 * @LastEditors: NtyAaron
 * @LastEditTime: 2021-04-27 21:22:14
 * @Description: file content
 * @FilePath: \dwq\pages\my\myFoot\myFoot.js
 */

import { getFootprintList, delFootprint } from '../../../api/user/user'
import Dialog from '../../../miniprogram_npm/@vant/weapp/dialog/dialog'
import { _t } from '../../../i18n/base'
Page({
  data: {
    footList: [
      {
        title: '广东省人才优粤卡申办',
        way: '广东省人力资源和社会保障厅',
      },
    ],
    messagePath: '/pages/my/myCollect/myCollect',
    messageImg: '/images/logo新.png',
  },
  // 删除足迹
  async delFootprint(e) {
    const { instance } = e.detail
    let id = e.currentTarget.dataset.id
    let { result } = await delFootprint({ ids: id })
    if (result) {
      instance.close()
      this.getFootprintList()
    }
  },
  // 跳转客服详情
  toCustomerServiceHandle(e) {
    let detail = e.currentTarget.dataset.info
    Dialog.confirm({
      title: this.data.lang['查看内容'],
      message: this.data.lang['跳转内容链接'],
      confirmButtonText: this.data.lang['确定'],
      cancelButtonText: this.data.lang['取消'],
      confirmButtonOpenType: 'contact',
      sendMessageTitle: `${detail.title}(${detail.articleId})`,
      sendMessagePath: this.data.messagePath,
      sendMessageImg: this.data.messageImg,
      showMessageCard: true,
    })
      .then(async () => {
        setTimeout(() => {
          console.log(12)
        })
      })
      .catch(() => {})
  },
  // 获取足迹列表
  async getFootprintList() {
    let userInfo = wx.getStorageSync('userInfo')
    if (userInfo) {
      let user = JSON.parse(userInfo)
      let { result } = await getFootprintList({ userId: user.userId })
      this.setData({
        footList: result,
      })
    }
  },
  async onLoad(e) {
    let lang = _t()
    this.setData({
      lang,
    })
    wx.setNavigationBarTitle({
      title: this.data.lang['我的足迹'],
    })
    this.getFootprintList()
  },
})
